package fr.azzale.casu.utils;

import fr.azzale.casu.activity.TribuneActivity;
import android.os.AsyncTask;
import android.view.View;

public class PostMessageASync extends AsyncTask<String, Void, String> {

	private TribuneActivity ctx;

	public PostMessageASync(TribuneActivity tribuneActivity) {
		this.ctx = tribuneActivity;
	}

	@Override
	protected String doInBackground(String... params) {
		for(String param: params)
			return Utils.postMessage(ctx, param, Utils.getSessionID(ctx), ctx.getRow());
		return null;
				
	}

	@Override
	protected void onPreExecute() {
		ctx.getLineEdit().setEnabled(false);
		ctx.getSpinner().setVisibility(View.VISIBLE);
	}

	@Override
	protected void onPostExecute(String result) {
		if(result!=null)
		{
			ctx.setErrorMessage(result);
			ctx.showDialog(TribuneActivity.DIALOG_ERREUR);
		}
		ctx.getSpinner().setVisibility(View.GONE);
		ctx.getLineEdit().setEnabled(true);
	}

}
